<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="divat-detection" content="telephone=no,email=no" />
		<title>找回密码</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link href="css/account.css" rel="stylesheet"/>
	</head>
	<body>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> 			
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content">
			<div id="password-div" class="mui-input-group">
				<div class="mui-input-row">
					<input type="number" id="teleEmail" class="mui-input mui-input-clear" placeholder="输入手机号码"/>
				</div>
				<div class="mui-input-row">
						<input type="password"id="newPassword" class="mui-input mui-input-clear mui-password"  placeholder="新密码"/>
				</div>
				<div class="mui-input-row">
					<input type="password" id="confirmPassword" class="mui-input mui-input-clear mui-password" placeholder="确认密码"/>
					
				</div>
				<div class="mui-input-row">	
					<input id="code" type="number" placeholder='请输入验证码' class="mui-input input-half" /><a class="input-btn" id="getCode">获取验证码</a>
				</div>
			</div>
			<div class="mui-content-padded">
				<button class="mui-btn mui-btn-block mui-btn-danger" id="nextStep1">确认修改</button>
			</div>
		</div>
		
	
	</body>
</html>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script>
	mui.init({swipeBack: true});
	mui.plusReady(function() {				
		var code=document.getElementById("code");
		var teleEmail=document.getElementById("teleEmail");
		var nextStep1=document.getElementById("nextStep1");
		var countTime=document.getElementById("countTime");
		var newPassword=document.getElementById('newPassword')
		var confirmPassword=document.getElementById('confirmPassword')
		var time;
		var	flag=false;
		getCodeFn('phone','teleEmail');
		nextStep1.addEventListener('tap',function(){						
			
			if(teleEmail.value==""){
				plus.nativeUI.toast('请填写手机');
				return;
			};
			if(newPassword.value.length < 6){
					plus.nativeUI.toast('新密码最短为 6 个字符');
					return;
			};
			if (confirmPassword.value != newPassword.value) {
				plus.nativeUI.toast('新密码两次输入不一致');
				return;
			};
			if(code.value==""){
				plus.nativeUI.toast('验证码不能为空！');
				return;
			};
			console.log('hahah')
			var w=plus.nativeUI.showWaiting('',{padlock:true});
			console.log(confirmPassword.value+'密码')
			console.log(teleEmail.value+'手机')
			console.log(code.value+"验证码")
			mui.ajax(url+'UserCenter/SetPassword',{
				data:{	
					webToken:'rqlh',
					password:confirmPassword.value,
					mobile:teleEmail.value,
					code:code.value,
					type:2
				},																																																					
				dataType:'json',  
				type:'post',      
				timeout:10000, 
				success:function(data){
					w.close();
					if(data.Code=='000'){	
						console.log(data.Msg);
						plus.nativeUI.toast('密码修改成功')		
						mui.back();
					}else{
						plus.nativeUI.toast(data.Msg);											
						
					} 
				},  
				error:function(xhr,type,errorThrown){
					console.log('cuowu')
					w.close();					 
								
			 	}
			}); 
		})
		/*发送验证码*/
		function getCodeFn(type,contact){
			var getCode=document.getElementById("getCode"),
			contactEl=document.getElementById(contact),
//						codeEl=(code?document.getElementById(code):null),
			flag=false;
			getCode.addEventListener("tap",function(){
				var contact=contactEl.value,
					data={};
				if(flag)
					return;	
				if(type=='phone'){
//							var checkCode=codeEl.value;
					if(contact.length != 11){
						plus.nativeUI.toast('手机号码为11位');
							return;
					}	
						data={contact:contact};
				}else{
					if (!himall.checkEmail(contact)) {
						plus.nativeUI.toast('请输入正确的邮箱地址');
						return;
					}
						data={contact:contact};
				}
				var rqlx='rqlx'
				var w=plus.nativeUI.showWaiting('',{padlock:true});

				console.log(contact);
				console.log("验证码发送");
				mui.ajax('http://122.114.101.135/app/version/authcode',{
					data:{	
						phone:contact,
						type:'2'
					},																																																					
					dataType:'json',  
					type:'Get',     
					timeout:10000,
					success:function(data){
						w.close();
						console.log(data.msg);
						console.log(data.data.random);
						console.log(data.data.result)
						pcode=data.data.random;
						console.log(data.msgcode)
						if(data.msgcode==1){									
							flag=true;
		 					var total=60;
							
							plus.nativeUI.toast('验证码已发送，请注意查收');
							time=setInterval(function(){
								if(total>0){
									total--;
									getCode.innerText=total+'s后可重发';
								}else{
									getCode.innerText='重新发送';
									clearInterval(time);
									flag=false;
								}  
							},1000)	
							
									 	
						}else{
							plus.nativeUI.toast(data.msg);											
							console.log(data.Success);
							console.log(data.ErrorMsg);
						} 
					}, 
					error:function(xhr,type,errorThrown){
						plus.nativeUI.toast('验证码发送失败');
						w.close();
						console.log("失败"+xhr+"2:"+type+"3:"+errorThrown);
						for(var k in xhr) {								 	
			    //遍历对象，k即为key，obj[k]为当前k对应的值
						    console.log(k+xhr[k]);						 
						}	
									
				 	}
				}); 

			}); 	  
		}

		 
	})
		
</script>